package main.java.indi.zyj.hot100;

public class _57_maxProduct {

    public int maxProduct(int[] nums) {

        int max = Integer.MIN_VALUE, iMax = 1, iMin = 1, temp;

        for (int i = 0; i < nums.length; i++) {
            if (nums[i] < 0){
                temp = iMax;
                iMax = iMin;
                iMin = temp;
            }
            iMax = Math.max(iMax * nums[i], nums[i]);
            iMin = Math.min(iMin * nums[i], nums[i]);
            max = Math.max(max, iMax);
        }
        return max;
    }
}
